import { login } from '@/api/user'
import { setToken, getToken, removeToken } from '@/utils/auth'
const state = {
  token: getToken()
}

const mutations = {
  login(state, payload) {
    state.token = payload
    setToken(payload)
  },
  logout(state) {
    state.token = null
    removeToken()
  }
}

const actions = {
  async login(context, payload) {
    const res = await login(payload)
    // console.log(res)
    context.commit('login', res.token)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

